package top.sdaily.web.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.sdaily.web.context.ReturnBody;
import top.sdaily.web.model.Dict;
import top.sdaily.web.service.DictService;

/**
 * Created by soya on 2017/1/24.
 */
@RestController
@RequestMapping("dict")
public class DictController {

    @Autowired
    DictService dictService;

    @GetMapping
    public ReturnBody getRootDicts() {
        return ReturnBody.success().setData(dictService.getAll());
    }

    @PostMapping
    public ReturnBody create(@RequestBody Dict dict){
        dictService.create(dict);
        return ReturnBody.success().setData(dict);
    }

    @PutMapping
    public ReturnBody modify(@RequestBody Dict dict){
        dictService.modify(dict);
        return ReturnBody.success().setData(dict);
    }

    @DeleteMapping("/{pkid}")
    public ReturnBody del(@PathVariable String pkid){
        dictService.delete(pkid);
        return ReturnBody.success();
    }

    @GetMapping("/{pkid}/node")
    public ReturnBody getByParent(@PathVariable String pkid){
        return ReturnBody.success().setData(dictService.getByParent(pkid));
    }

}
